<%--
  Created by IntelliJ IDEA.
  User: 李林
  Date: 2020/3/11
  Time: 22:42
  To change this template use File | Settings | File Templates.
--%>
<%--思路 不想每次都修改权限表 将权限那栏放在from表单外 当没有点击修改权限时 提交from表单
    当点击了修改权限时 替换掉提交表单的方法 加上提交设置的权限
    --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
修改用户界面
<form id="modifyForm" >
    <input type="hidden" name="uid" value="${userInfo.uid}">
    用户名：<input type="text" name="username" value="${userInfo.username}"><br>
    姓名：<input type="text" name="name" value="${userInfo.name}"><br>
    性别：<input type="radio" name="gender" value="1" checked="checked" ${userInfo.gender == 1?'checked':''}>男
    <input type="radio" name="gender" value="2" ${userInfo.gender == 2?'checked':''}>女<br/>
    邮箱：<input type="text" name="email"  value="${userInfo.email != null?userInfo.email:'null'}"><br>
    电话：<input type="text" name="phoneNum"  value="${userInfo.phoneNum!= null?userInfo.phoneNum:'null'}"><br>
    日期：<input type="date" name="date" value="<fmt:formatDate value='${userInfo.date}' pattern="yyyy-MM-dd"/>" >
    管理权限：
    <c:forEach items="${userInfo.roles}" var="role"  varStatus="roleStatus">
    <span>
            <c:if test="${roleStatus.last}">
                ${role.roleDesc}
            </c:if>
            <c:if test="${!roleStatus.last}">
                ${role.roleDesc}/
            </c:if>
        </c:forEach><br>
    </span>
</form>
    <security:authorize access="hasRole('ROLE_MANAGER')">
    <div >
        <li id="unstatus" class="treeview">
            <a href="javascript:void(0)" onclick="showunstatus(${userInfo.uid})">
                <i class="fa fa-th-list"></i> <span>修改权限</span>
                <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                    </span>
            </a>
            <div id="unstatus-ul">
            </div>
            <%--<ul class="treeview-menu">--%>
                          <%--<li id="news-manager">--%>
                                    <%--<input type="checkbox" name="admin" checked="checked" class="role,role-roles[i].id" value="value">"--%>
                                        <%--<i class="fa fa-circle-o"></i>--%>
                               <%--</li>--%>
                        <%--</ul>;--%>
        </li>
    </div>
    </security:authorize>
    <!--工具栏onclick="modifyuserdo()"-->

    <div class="box-tools text-center">
        <button id="from_button" type="button" class="btn bg-maroon" >保存</button>
        <button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
    </div>

<script>
    function modifyuserdo() {
        $.post("usermodify.do",$("#modifyForm").serialize(),function (data) {
            alert(data);
            $.get("user",{},function (data) {
                $(".onjsp").html(data);
            })
        })
    }
    function modifyusersdo() {
        // alert("modifyusersdo");
        var check_boxs = document.getElementsByName('admin');
        var check_value = [];
        alert("length:"+check_boxs.length)
        for(var i = 0;i<check_boxs.length;i++){
            // alert("check_box:"+check_boxs[i])
            if(check_boxs[i].checked){
                alert("check_value:"+check_boxs[i].value)
                check_value.push(check_boxs[i].value);
            }
        }
        if(check_value.length==0){
            alert("至少选一个");
            return;
        }
        var check_str = check_value.join("&admin=");
        alert("join hou "+check_str)
        // var username = $("#modifyForm").serialize()+"&admin="+check_str;
        var username = $("#modifyForm").serialize()
        alert(username);
        $.post("usermodstatus.do",username,function (data) {
            // alert("modifyusersdo");
            $.get("user",{},function (data) {
                $(".onjsp").html(data);
            })
        })
    }
    function showunstatus(uid) {
        $("#from_button").attr('onclick', '').unbind('click');
        $("#from_button").click(modifyusersdo);
        $.post("roleall",{"uid":uid},function (resultMap) {
            var roles = resultMap.resultList["roles"];
            var ul = '';
            for (var i =0 ;i<roles.length ;i++){
                var li = '<ul class="treeview-menu">\n' +
                    '                <li id="news-manager">\n' +
                    '                    <input type="checkbox" name="admin" checked="checked" class="role,role-'+roles[i].id+'" value="'+roles[i].id+'"> \n' +
                    '                        <i class="fa fa-circle-o"></i> '+roles[i].roleDesc+
                    '                </li>\n' +
                    '            </ul>';
                ul+=li;
            }
            $("#unstatus-ul").html(ul);
        });

    }
</script>
<%--// var useroles = resultMap.resultList["useroles"];--%>
<%--// // var checkbox = document.getElementById('vegeids');--%>
<%--// var checkbox = document.getElementsByName("admin");--%>
<%--// if(checkbox.checked){--%>
<%--//     for(i=0;i<boxes.length;i++){--%>
<%--//         boxes[i].checked = true;--%>
<%--//     }--%>
<%--// }    else{--%>
<%--//     $(":checkbox").attr("checked", false);--%>
<%--// }--%>
<%--//--%>
<%--// for (var i = 0 ;i<useroles.length;i++){--%>
<%--//--%>
<%--// }--%>